package com.ruoyi.web.controller.mobile;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mobile.domain.UserPoint;
import com.ruoyi.mobile.service.IUserPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户运动打分Controller
 * 
 * @author ruoyi
 * @date 2022-10-05
 */
@RestController
@RequestMapping("/mobile/point")
public class UserPointController extends BaseController
{
    @Autowired
    private IUserPointService userPointService;

    /**
     * 查询用户运动打分列表
     */
    @PreAuthorize("@ss.hasPermi('mobile:point:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserPoint userPoint)
    {
        startPage();
        List<UserPoint> list = userPointService.selectUserPointList(userPoint);
        return getDataTable(list);
    }

    /**
     * 导出用户运动打分列表
     */
    @PreAuthorize("@ss.hasPermi('mobile:point:export')")
    @Log(title = "用户运动打分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserPoint userPoint)
    {
        List<UserPoint> list = userPointService.selectUserPointList(userPoint);
        ExcelUtil<UserPoint> util = new ExcelUtil<UserPoint>(UserPoint.class);
        util.exportExcel(response, list, "用户运动打分数据");
    }

    /**
     * 获取用户运动打分详细信息
     */
    @PreAuthorize("@ss.hasPermi('mobile:point:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(userPointService.selectUserPointById(id));
    }

    /**
     * 新增用户运动打分
     */
    @PreAuthorize("@ss.hasPermi('mobile:point:add')")
    @Log(title = "用户运动打分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserPoint userPoint)
    {
        return toAjax(userPointService.insertUserPoint(userPoint));
    }

    /**
     * 修改用户运动打分
     */
    @PreAuthorize("@ss.hasPermi('mobile:point:edit')")
    @Log(title = "用户运动打分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserPoint userPoint)
    {
        return toAjax(userPointService.updateUserPoint(userPoint));
    }

    /**
     * 删除用户运动打分
     */
    @PreAuthorize("@ss.hasPermi('mobile:point:remove')")
    @Log(title = "用户运动打分", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(userPointService.deleteUserPointByIds(ids));
    }
}
